<template>
  <div>
    <el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" :visible ="showDialog" title="修改">
      <el-form ref="formRef" :model="forms" :rules="rules" size="medium" label-width="100px"
        label-position="left">
        <el-form-item label="学科名称" prop="subjectName">
          <el-input v-model="forms.subjectName" placeholder="请输入单行文本学科名称" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="开关">
          <el-switch
           v-model="forms.isFrontDisplay"
           :active-value="1"
           >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { update } from '../../api/hmmm/subjects'
export default {
  name: 'tanchuang',
  inheritAttrs: false,
  components: {},
  props: {
    showDialog: {
      type: Boolean,
      required: true
    },
    forms: {
      type: Object,
      required: true
    }
    // isShow: {
    //   type: Boolean,
    //   required: true
    // }

  },
  data () {
    return {
      // form: {
      //   forms: this.forms
      // },
      // 表单校验规则
      rules: {
        subjectName: [
          { required: true, message: '请输入学科名称', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  created () {
    // console.log(this.showDialog)

    // const res = await updated()
    // console.log(res)
    // this.formData = data.data
  },
  mounted () {
  },
  methods: {
    onOpen () {

    },
    onClose () {
    //   this.$refs.formRef.resetFields()
      this.close()
    },
    close () {
      this.$emit('update:forms', {})
      // this.$emit('update:isShow', false)
      this.$emit('update:showDialog', false)
    },
    async handelConfirm () {
      // 调用添加接口修改数据
      await update(this.forms)
      this.$emit('update:showDialog', false)
      // 更新视图列表
      this.$emit('list')
      this.$message.success('修改成功')

      // 修改成功后把数据清零
      this.$emit('update:forms', {})
      // this.$emit('update:isShow', false)
      this.close()
      // this.$refs.formRef.validate(valid => {
      //   if (!valid) return
      //   this.close()
      // })
    }
  }
}

</script>
<style>
</style>
